package com.tanquandan.askbackend.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tanquandan.askbackend.dao.CourseMapper;
import com.tanquandan.askbackend.dao.KeywordMapper;
import com.tanquandan.askbackend.dto.KeywordDto;
import com.tanquandan.askbackend.dto.R;
import com.tanquandan.askbackend.entity.Course;
import com.tanquandan.askbackend.entity.Keyword;
import com.tanquandan.askbackend.service.IKeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class KeywordService extends ServiceImpl<KeywordMapper, Keyword> implements IKeywordService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public R<List<KeywordDto>> listKeywordCourseList() {
        List<Keyword> keywordList = list();
        List<KeywordDto> KeywordDtoList = new ArrayList<>();
        for (Keyword keyword : keywordList) {
            KeywordDto keywordDto = new KeywordDto();
            List<Course> courses = courseMapper.listCourseByKeyword(keyword.getId());
            BeanUtil.copyProperties(keyword,keywordDto);
            keywordDto.setCourseList(courses);

            KeywordDtoList.add(keywordDto);
        }
        return R.success(KeywordDtoList);
    }
}
